<?php
class cs_twitter_widget extends WP_Widget
{
  function cs_twitter_widget()
  {
    $widget_ops = array('classname' => 'cs_twitter_widget', 'description' => 'Twitter Widget feeds' );
    $this->WP_Widget('cs_twitter_widget', 'ChimpS : Twitter Widget', $widget_ops);
  }
 
  function form($instance)
  {
    $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
    $title = $instance['title'];
	$t_img_url = isset( $instance['t_img_url'] ) ? esc_attr( $instance['t_img_url'] ) : '';
?>
  <p>
  <label for="<?php echo $this->get_field_id('title'); ?>">
	  <span>Twitter Username </span><br />
	  <span>http://www.twitter.com/your-username  - Only {your-username}</span>
	  <input class="upcoming" id="<?php echo $this->get_field_id('title'); ?>" size="40" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
  </label>
  </p>
  <p>
  <label for="<?php echo $this->get_field_id('t_img_url'); ?>">
	  <span>Background Url: </span>
	  <input class="upcoming" id="<?php echo $this->get_field_id('t_img_url'); ?>" size="40" name="<?php echo $this->get_field_name('t_img_url'); ?>" type="text" value="<?php echo esc_attr($t_img_url); ?>" />
  </label>
  </p>
<?php
  }
 
  function update($new_instance, $old_instance)
  {
    $instance = $old_instance;
    $instance['title'] = $new_instance['title'];
    $instance['t_img_url'] = $new_instance['t_img_url'];	
    return $instance;
  }
 
	function widget($args, $instance)
	{
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
	 
		// WIDGET display CODE Start
		if (!empty($title))
			echo $before_widget;
			//echo $before_title .$title. $after_title;
//			echo '<div class="tweet-banners"><a href="#" class="thumb"><img src="'.$instance['t_img_url'].'" alt="" /><span>&nbsp;</span></a>';
//			echo "<div class='scroll-sec'>";
			                    
			$username = $instance['title'];
			if($username != ''){?>
                	<a class="thumb"><img src="<?php echo $instance['t_img_url'];?>" alt="" width="300" height="188"/></a>
                    <!-- Twitter Scroll Start -->
                    <div class="scroll-sec">
                    	<div id="tweet-links"></div>
                        	<a href="http://www.twitter.com/<?php echo $username;?>" target="_blank" class="follow">Follow Us Twitter</a>
                        </div>
                    <!-- Twitter Scroll End -->
				<script type="text/javascript" src="<?php echo get_template_directory_uri()?>/scripts/frontend/jquery.tweetable.js"></script>
				<script type="text/javascript">
                    $(function(){
                        $('#tweet-links').tweetable({username: '<?php echo $username;?>', time: true, limit: 1, replies: true, position: 'append'});
                    });
                </script>
                <!-- Twitter End -->						
			<?php }else{ ?>
            <h1 class="heading">Twitter Widget</h1>
                <div class="list-thumb">
                    <ul>
                        <li>
                            <h2>No User information given.</h2>
                        </li>
                    </ul>
                </div>
<?php
			}
			echo $after_widget;
		// WIDGET display CODE End
		}
	}
add_action( 'widgets_init', create_function('', 'return register_widget("cs_twitter_widget");') );?>